{% if users %}
<script>
$(function () {
	var id = null;
	// verify user
	$('.icon-user').closest('li').click(function() {
		id = $(this).closest('tr').attr('id');
		$('.modal.verify-user').modal({ keyboard: false }, 'show');
	});
	$('.btn.verify-submit').click(function() {
		var result = ($(this).hasClass('btn-success')) ? 'success-verify' : 'fail-verify';
		$.post("{{ path('AcmeUserBundle_UserVerify') }}", { id: id, result: result },
		function (data) {
			if (data == 'success') {
				$('.btn.verify-submit').button('reset');
				$('.modal.verify-user').modal('hide');
				$('.btn.list-submit').trigger('click');
			}
		});
		id = null;
	});

	// edit user
	$('.icon-pencil').closest('li').click(function() {
		id = $(this).closest('tr').attr('id');
		$.post("{{ path('AcmeUserBundle_UserEdit') }}", { id: id, show_modal_request: true },
		function (html) {
			$('.modal.edit-user div.modal-body').html(html);
			$('.modal.edit-user').modal({ keyboard: false }, 'show');
		}, "html");
	});
	$('.btn.edit-submit').click(function() {
		$.post("{{ path('AcmeUserBundle_UserEdit') }}", $('.modal.edit-user form').serialize(),
		function (data) {
			if (data == 'success') {
				$('.btn.edit-submit').button('reset');
			}
		});
		id = null;
	});
	
	// delete user
	$('.icon-trash').closest('li').click(function() {
		id = $(this).closest('tr').attr('id');
		$.post("{{ path('AcmeUserBundle_UserDelete') }}", { id: id },
		function (data) {
			if (data == 'success') {
				$('.btn.list-submit').trigger('click');
			}
		});
		id = null;
	});

	// undelete user
	$('.icon-refresh').closest('li').click(function() {
		id = $(this).closest('tr').attr('id');
		$.post("{{ path('AcmeUserBundle_UserUndelete') }}", { id: id },
		function (data) {
			if (data == 'success') {
				$('.btn.list-submit').trigger('click');
			}
		});
		id = null;
	});
});
</script>

<table class="table table-striped" >
<caption><span style="color: red;">**</span>: 帐号由系统管理院创建, <span style="color: red;">*</span>: 帐号由学校管理院创建, -: 未定义, ?: 未填写</caption>
	<thead>
		<tr>
			<th>用户ID</th>
			<th>用户名</th>
			<th>真实姓名</th>
			<th>用户类型</th>
			<th>用户状态</th>
			<th>邮箱状态</th>
			<th>标记</th>
			<th>所在大学</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody>
		{% for user in users %}
		<tr id="{{ user.id }}">
			<td>{{ user.id }}</td>
			<td>
				{{ user.username }}
				{% if (user.createdBy != user.id) %}
				<span style="color: red;">*{% if (user.createdBy == 0) %}*{% endif %}</span>
				{% endif %}
			</td>
			{% if (userCategoryEn[user.category] == 'student' or userCategoryEn[user.category] == 'teacher') %}
			<td>{% if (user.userInfo.name) %}{{ user.userInfo.name }}{% else %}?{% endif %}</td>
			{% else %}
			<td>-</td>
			{% endif %}
			<td>{{ userCategory[user.category] }}</td>
			<td>{{ userStatus[user.userStatus] }}</td>
			<td>{{ emailStatus[user.emailStatus] }}</td>
			<td>{{ flag[user.flag] }}</td>
			<td>{% if (user.userInfo) %}{{ user.userInfo.universityInfo.name }}{% else %}-{% endif %}</td>
			<td>
			<div class="btn-group">
				<a href="#" class="btn btn-mini btn-primary"><i class="icon-user icon-white"></i> 用户管理</a>
				<a href="#" data-toggle="dropdown" class="btn btn-mini btn-primary dropdown-toggle"><span class="caret"></span></a>
				<ul class="dropdown-menu">
					{% if (flagEn[user.flag] == 'not-delete') %}
						<li><a href="#"><i class="icon-pencil"></i> 编辑</a></li>
						<li><a href="#"><i class="icon-trash"></i> 删除</a></li>
						
						{% if (userStatusEn[user.userStatus] == 'to-verify') %}
						<li class="divider"></li>
						<li><a href="#"><i class="icon-user"></i> 审核</a></li>
						{% endif %}
						
					{% else %}
						<li><a href="#"><i class="icon-refresh"></i> 还原</a></li>
					{% endif %}
				</ul>
	        </div>
			</td>
		</tr>
		{% endfor %}
	</tbody>
</table>

<div class="modal hide verify-user">
	<div class="modal-header">
		<a class="close" data-dismiss="modal">×</a>
		<h3>用户审核</h3>
	</div>
    <div class="modal-body">
    请选择用户审核结果
    </div>
    <div class="modal-footer">
	    <a href="#" class="btn" data-dismiss="modal">关闭</a>
	    <input class="btn btn-danger verify-submit" autocomplete="off" type="button" data-loading-text="提交中..." onclick="$(this).button('loading');" value="失败" />
		<input class="btn btn-success verify-submit" autocomplete="off" type="button" data-loading-text="提交中..." onclick="$(this).button('loading');" value="成功" />
    </div>
</div>

<div class="modal hide edit-user">
	<div class="modal-header">
		<a class="close" data-dismiss="modal">×</a>
		<h3>编辑用户信息</h3>
	</div>
    <div class="modal-body">
    </div>
    <div class="modal-footer">
	    <a href="#" class="btn" data-dismiss="modal">关闭</a>
	    <input class="btn btn-primary edit-submit" autocomplete="off" type="button" data-loading-text="保存中..." onclick="$(this).button('loading');" value="保存" />
    </div>
</div>
{% else %}
No user have been found.
{% endif %}